# 类说明：数据元素类型
# 类释义：该类拥有带排序的关键字key
class StaticTableElement(object):
    def __init__(self, key):
        self.key = key


# 类名称：SSTable
# 类说明：静态查找表的顺序存储结构
# 类释义：该类拥有一个数据元素类型的列表data和data的长度length
class StaticTable(object):
    def __init__(self):
        self.data = []
        self.length = 0

    # 创建数据元素类型列表
    def CreateSequenceTable(self, elements):
        self.length = len(elements)
        for i in range(self.length):
            self.data.append(StaticTableElement(elements[i]))

    # 打印待排序列表集合
    def TraverseSequenceTable(self):
        print("待排序列表为：")
        for i in range(self.length):
            print(self.data[i].key, end="\t")
        print()

    # 顺序查找函数
    def SequenceSearch(self, key):
        iPos = -1
        for i in range(self.length):
            if self.data[i].key == key:
                iPos = i
                break
        return iPos

    # 判断排序列表集合是否为空
    def SequenceIsEmpty(self):
        if self.length == 0:
            print("SST为空")
        else:
            print("SST不为空")


# 主程序
STdata = [1, 3, 5, 9, 16, 25]
ST = StaticTable()  # (2)
ST.CreateSequenceTable(STdata)
ST.SequenceIsEmpty()
ST.TraverseSequenceTable()
while True:
    iKey = input("请输入待查找关键字(#退出):")
    if iKey == '#':
        break
    STKey = int(iKey)
    STPos = ST.SequenceSearch(STKey)
    if STPos == -1:
        print("在静态查找表中未找到关键字", STKey)
    else:
        print("关键字", STKey, "在静态查找表中的位置为：", STPos)
